
import user.zc.helper.ExcelAssistant;
import user.zc.helper.IExcelMode;
import user.zc.excel.data.style.IStyle;
import lombok.SneakyThrows;
import org.apache.poi.ss.usermodel.IndexedColors;

import java.math.BigDecimal;


@ExcelAssistant(title = "个人信息（姓名，年龄，身份证）",column = @ExcelAssistant.Style(font = @ExcelAssistant.Style.Font(height = (short)20)))
public class ExcelData implements IExcelMode<ExcelData>{
    @ExcelAssistant(title = "姓名",column = @ExcelAssistant.Style(width = 2000,color = 14),rowSpanIfSameValue = true)
    public String name;
    @ExcelAssistant(title = "年龄",column = @ExcelAssistant.Style(width = 2000))
    public Integer age;
    @ExcelAssistant(title = "身份证",column = @ExcelAssistant.Style(width = 8000),cell = @ExcelAssistant.Style(alignment = 1 ))
    public String idCard;
    @ExcelAssistant(title = "语文",mergeRelationColumn = "成绩",column = @ExcelAssistant.Style(width = 2000))
    public Integer chinese;
    @ExcelAssistant(title = "数学",mergeRelationColumn = "成绩",column = @ExcelAssistant.Style(width = 2000))
    public Integer math;
    @ExcelAssistant(title = "性別",column = @ExcelAssistant.Style(width = 2000))
    public String sex;
    @ExcelAssistant(title = "余额",column = @ExcelAssistant.Style(width = 4000))
    public BigDecimal money;
    public ExcelData(String name, Integer age, String idCard, Integer chinese, Integer math, String sex, BigDecimal money) {
        this.name = name;
        this.age = age;
        this.idCard = idCard;
        this.chinese = chinese;
        this.math = math;
        this.sex = sex;
        this.money = money;
    }

    @Override
    public void update() {
        if(this.idCard != null){
            this.idCard = this.idCard.substring(0,10)+"****"+this.idCard.substring(14,18);
        }
    }

    @Override
    @SneakyThrows
    public IStyle.StyleInfo style(Integer i,ExcelData item,String name, Object value) {
        IStyle.StyleInfo styleInfo =  IStyle.StyleInfo.newEmpty();
        if(name.equals("math") || name.equals("chinese")){
            Integer math = (Integer)value;
            if(math<60){
                styleInfo.getFont().setColor(IndexedColors.GREY_50_PERCENT.index);
            }
            if(math>90){
                styleInfo.getFont().setColor(IndexedColors.RED.index);
                styleInfo.getFont().setBold(true);
            }
        }
        return styleInfo;
    }

}